package com.wangchao.administrator.zenmechi.ui.specialactivity;

import android.content.Context;
import android.util.Log;

import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.wangchao.administrator.zenmechi.bean.special.SpecialBean;

import java.util.HashMap;
import java.util.Map;

import rx.Subscriber;

/**
 * Created by My on 2016/10/19.
 */
public class SpecialPresenter implements SpecialContract.Presenter {
    private SpecialContract.Model model;
    private SpecialContract.View view;

    public SpecialPresenter( SpecialContract.View view) {
        this.model = new SpecialModel();
        this.view = view;
    }

    @Override
    public void setListadpter(final PullToRefreshListView pullToRefreshListView,
                              final Context context) {
//        market_id=6&page=1&page_size=1000
        Map<String ,String> map=new HashMap<>();
        map.put("market_id","6");
        map.put("page","1");
        map.put("page_size","1000");
        Log.i("aaa",map.toString());
                model.getNetworkDate(new Subscriber<SpecialBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.i("aaa",e.toString());

                    }

                    @Override
                    public void onNext(SpecialBean specialBean) {
                        view.onSuccess(specialBean);
                        if (specialBean!=null&&specialBean.getResult()!=null&&
                                specialBean.getResult().getData()!=null&&
                                specialBean.getResult().getData().size()!=0
                                )
                        pullToRefreshListView.setAdapter(new ListSpecAdapter(
                                specialBean.getResult().getData(),context
                        ));
                    }
                }, map);
    }


}
